package com.fun_ordering.service.impl;

import com.fun_ordering.service.EmployeeTaskService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.fun_ordering.components.PageResult;
import com.fun_ordering.mapper.EmployeeTaskMapper;
import com.fun_ordering.pojo.EmployeeTask;
import com.fun_ordering.pojo.EmployeeTaskExample;
import com.fun_ordering.pojo.EmployeeTaskExample.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 员工任务表服务实现层
 * @author XiaoPi
 *
 */
@Service
public class EmployeeTaskServiceImpl implements EmployeeTaskService {

	@Autowired
	private EmployeeTaskMapper employeeTaskMapper;
	
	/**
	 * 查询全部
	 */
	@Override
	public List<EmployeeTask> findAll() {
		return employeeTaskMapper.selectByExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);		
		Page<EmployeeTask> page=   (Page<EmployeeTask>) employeeTaskMapper.selectByExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(EmployeeTask employeeTask) {
		employeeTaskMapper.insert(employeeTask);		
	}

	
	/**
	 * 修改
	 */
	@Override
	public void update(EmployeeTask employeeTask){
		employeeTaskMapper.updateByPrimaryKey(employeeTask);
	}	
	
	/**
	 * 根据ID获取实体
	 * @param taskId
	 * @return
	 */
	@Override
	public EmployeeTask findOne(Integer taskId){
		return employeeTaskMapper.selectByPrimaryKey(taskId);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(Integer[] taskIds) {
		for(Integer taskId:taskIds){
			employeeTaskMapper.deleteByPrimaryKey(taskId);
		}		
	}
	
	
		@Override
	public PageResult findPage(EmployeeTask employeeTask, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		
		EmployeeTaskExample example=new EmployeeTaskExample();
		Criteria criteria = example.createCriteria();
		
		if(employeeTask!=null){			
						if(employeeTask.getContent()!=null && employeeTask.getContent().length()>0){
				criteria.andContentLike("%"+employeeTask.getContent()+"%");
			}			if(employeeTask.getReleaseName()!=null && employeeTask.getReleaseName().length()>0){
				criteria.andReleaseNameLike("%"+employeeTask.getReleaseName()+"%");
			}			if(employeeTask.getStatus()!=null && employeeTask.getStatus().length()>0){
				criteria.andStatusLike("%"+employeeTask.getStatus()+"%");
			}	
		}
		
		Page<EmployeeTask> page= (Page<EmployeeTask>)employeeTaskMapper.selectByExample(example);
		return new PageResult(page.getTotal(), page.getResult());
	}
	
}
